home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 July / macformat-026.iso / mac / Shareware City / Graphics / PS2EPS+ 1.0 Folder / GS / PS / gs_fonts.ps next >
Encoding:
Text File  |  1993-01-20  |  4.9 KB  |  164 lines  |  [TEXT/R*ch]

  1. %    Copyright (C) 1990, 1991 Aladdin Enterprises.  All rights reserved.
  2. %    Distributed by Free Software Foundation, Inc.
  3. %
  4. % This file is part of Ghostscript.
  5. %
  6. % Ghostscript is distributed in the hope that it will be useful, but
  7. % WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. % to anyone for the consequences of using it or for whether it serves any
  9. % particular purpose or works at all, unless he says so in writing.  Refer
  10. % to the Ghostscript General Public License for full details.
  11. %
  12. % Everyone is granted permission to copy, modify and redistribute
  13. % Ghostscript, but only under the conditions described in the Ghostscript
  14. % General Public License.  A copy of this license is supposed to have been
  15. % given to you along with Ghostscript so you can know your rights and
  16. % responsibilities.  It should be in a file named COPYING.  Among other
  17. % things, the copyright notice and this notice must be preserved on all
  18. % copies.
  19.  
  20. % Font initialization for Ghostscript.  Despite anything claimed below,
  21. % Ghostscript fonts are actually in the same format as Adobe Type 1 fonts,
  22. % except that the external form customarily does not use eexec encryption.
  23. % Someday there will be GNU documentation that describes this format.
  24. % Until then, you'll have to either get a copy of Adobe's book, or read
  25. % the Ghostscript code.  The interpreter for Type 1 fonts, which reveals
  26. % most of their structure, is in the file gstype1.c.
  27.  
  28.  
  29. % Define the default font.
  30. /defaultfontname /Ugly def
  31.  
  32.  
  33. % Internal procedure to load the font name -> font file name map
  34. % if it isn't loaded already, and push it on the stack.
  35. /Fontmap
  36.  { /FontFileMap where
  37.     { /FontFileMap get }
  38.     { (Fontmap) findlibfile not
  39.        { (Can't find ) print print (!\n) print stop }
  40.       if
  41.  
  42.       FontDirectory maxlength dict exch
  43.       2 dict begin
  44.         mark exch 2 index exch
  45.     /;
  46.      { % The stack contains a mark, the dictionary, the font name,
  47.        % the file name, and additional information about the font.
  48.        counttomark 3 sub { pop } repeat put
  49.        1 index
  50.      } bind def
  51.     run
  52.       end
  53.       pop pop        % pop the mark and the copy of the dictionary
  54.       userdict exch /FontFileMap exch put
  55.       FontFileMap
  56.      }
  57.    ifelse
  58.  } bind def
  59.  
  60.  
  61. % Define definefont.  This is a procedure built on an operator that
  62. % does all the error checking and key insertion.
  63. /definefont
  64.  { 1 dict begin count /d exch def    % save stack depth in case of error
  65.    { .buildfont readonly } stopped
  66.    { count d sub { pop } repeat end /invalidfont signalerror }
  67.    { end dup FontDirectory 4 2 roll put }
  68.    ifelse
  69.  } odef
  70.  
  71.  
  72. % Define findfont so it tries to load a font if it's not found.
  73. /findfont
  74.  {
  75.     % If the key is a string, convert it to a name for lookup.
  76.     dup type /stringtype eq { cvn } if
  77.  
  78.     % If the font isn't in FontDirectory already, load it.
  79.     dup FontDirectory exch known
  80.      { FontDirectory exch get
  81.      }
  82.      { dup        % save the font name on the stack
  83.  
  84.        % Push the font name -> font file name map on the stack,
  85.        % loading it if necessary.
  86.        Fontmap
  87.  
  88.        % Read the file name from the map.
  89.        % (The stack contains the font name and the font file map.)
  90.        1 index known not
  91.         { QUIET not
  92.            { (Substituting ) print defaultfontname cvx =only
  93.              ( for unknown font ) print == flush
  94.            } { pop } ifelse
  95.           pop defaultfontname findfont
  96.         }
  97.         { FontFileMap exch get
  98.  
  99.           % If we can't find the file, substitute for the font.
  100.           dup findlibfile
  101.            { QUIET not
  102.           { (Loading font file ) print exch print (... ) print flush }
  103.           { exch pop }
  104.          ifelse
  105.              mark exch
  106.            systemdict begin   run   end        % run can take a file
  107.          cleartomark
  108.          QUIET not
  109.           { vmstatus 3 { =only ( ) print } repeat
  110.             (done.\n) print flush
  111.           } if
  112.          findfont
  113.            }
  114.            { pop 1 index defaultfontname eq
  115.           { (Can't find default font!\n) print
  116.             pop pop NullFont
  117.           }
  118.           {
  119.             QUIET not
  120.             { (Can't find font file ) print print
  121.               (, substituting ) print defaultfontname cvx =only
  122.               (.\n) print flush } { pop } ifelse
  123.             pop defaultfontname findfont
  124.           }
  125.          ifelse
  126.            }
  127.           ifelse
  128.         }
  129.        ifelse
  130.  
  131.      } ifelse
  132.  
  133.  } bind def
  134.  
  135.  
  136. % The CharStrings for a Ghostscript font are a dictionary in which
  137. % the key is the character name, and the value is a compressed
  138. % representation of a path, as produced by type1imagepath.
  139. % For detailed information, see the book
  140. % "Adobe Type 1 Font Format", published by Adobe Systems Inc.
  141.  
  142. % Here is the BuildChar implementation
  143. % for Type 1 (Ghostscript standard) fonts.
  144. % The name Type1BuildChar is known to the interpreter.
  145.  
  146. /Type1BuildChar
  147.  { exch begin
  148.     Encoding exch get
  149.     dup CharStrings exch known not
  150.      { QUIET not
  151.         { (Substituting .notdef for ) print = flush
  152.     } { pop } ifelse
  153.        /.notdef
  154.      } if
  155.     CharStrings exch get
  156.     PaintType 0 ne
  157.      { 1 setmiterlimit 1 setlinejoin 1 setlinecap
  158.        currentdict /StrokeWidth known { StrokeWidth } { 0 } ifelse
  159.        setlinewidth }
  160.     if
  161.     type1addpath    % does a fill or stroke
  162.    end
  163.  } bind def
  164.